#!/usr/bin/env python
# -*- coding: utf-8 -*-
from flask_mail import Message
from flask import current_app
from applications.extensions.mail_plugin import mail


def send_email(to, subject, body):
    """
    发送普通邮件
    :param to: 收件人邮箱，字符串或列表
    :param subject: 邮件主题
    :param body: 邮件正文内容
    :return: True 表示成功，False 表示失败
    """
    try:
        if isinstance(to, str):
            to = [to]
        msg = Message(subject=subject, recipients=to, body=body)
        mail.send(msg)
        current_app.logger.info(f"邮件已发送至 {to}")
        return True
    except Exception as e:
        current_app.logger.error(f"邮件发送失败: {e}")
        return False
